package com.hulman.oms.web;

import com.hulman.oms.bean.Result;
import com.hulman.oms.bean.MonthReport;
import com.hulman.oms.service.MonthReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: maxwellens
 */
@RestController
public class MonthReportController
{
    @Autowired
    private MonthReportService monthReportService;

    @GetMapping("/month-reports/{id}")
    public Result findMonthReportById(@PathVariable Integer id)
    {
        MonthReport monthReport = monthReportService.findMonthReportById(id);
        return new Result(monthReport);
    }

    @GetMapping("/month-reports")
    public Result findMonthReports(Integer page, Integer limit, Integer year, Integer month, Integer createById, String createByName, Integer state)
    {
        Map<String, Object> map = new HashMap<>();
        map.put("page", page);
        map.put("limit", limit);
        map.put("year", year);
        map.put("month", month);
        map.put("createById", createById);
        map.put("createByName", createByName);
        map.put("state", state);
        return monthReportService.findMonthReportsResult(map);
    }

    @DeleteMapping("/month-reports/{id}")
    public Result deleteMonthReportById(@PathVariable Integer id)
    {
        monthReportService.deleteMonthReportById(id);
        return Result.SUCCESS;
    }

    @PutMapping("/month-reports")
    public Result saveMonthReport(MonthReport monthReport)
    {
        monthReportService.saveMonthReport(monthReport);
        return Result.SUCCESS;
    }

    @PostMapping("/month-reports/create")
    public Result create(MonthReport monthReport) throws IOException
    {
        monthReportService.create(monthReport);
        return Result.SUCCESS;
    }

    @PostMapping("/month-reports/submit")
    public Result submit(Integer id) throws IOException
    {
        monthReportService.submit(id);
        return Result.SUCCESS;
    }

}
